﻿namespace BEGDC.CC.Web.UserControls.EBDCV
{
    using System;
    using System.Data;
    using System.Collections;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Text;

    using BEGDC.CC.BL.CCFlow.EBDCV;
    using BEGDC.CC.BL.CCFlow.CR;
    using BEGDC.CC.Entity;
    using BEGDC.CC.BL.Workflow;
    using BEGDC.CC.BL.Common;
    using BEGDC.CC.BL.Common.Query;
    using BEGDC.CC.BL.UserManagement;
    using BEGDC.Utility.Castle;

    /// <summary>
    ///	Summary description for Apply.
    /// </summary>
    public class EBDCVCtrl : BaseEBDCV
    {
        #region ui control definition

        protected BEGDC.CC.Web.UserControls.Export ctrlExport;
        protected System.Web.UI.WebControls.Label Lb_CISWarning;
        protected System.Web.UI.WebControls.Label lbTitle;
        protected System.Web.UI.WebControls.RadioButtonList rbSomeoneElse;
        protected System.Web.UI.WebControls.TextBox tbSomeoneEmail;
        protected System.Web.UI.WebControls.TextBox tbCustomerName;
        protected System.Web.UI.WebControls.RadioButtonList rbIsFCPA;
        protected System.Web.UI.WebControls.TextBox tbCustomerCountry;
        protected System.Web.UI.WebControls.RadioButtonList rbReviewGuideLine;

        protected System.Web.UI.WebControls.TextBox tbVisitObjectives;
        protected System.Web.UI.WebControls.CheckBoxList cblPreferredLocation;
        protected System.Web.UI.WebControls.TextBox tbPotentialRevenue;
        protected System.Web.UI.WebControls.DropDownList ddlPotentialRevenueTime;
        protected System.Web.UI.WebControls.DropDownList ddlSaleStage;
        protected System.Web.UI.WebControls.RadioButtonList rbOutStandingRFP;
        protected System.Web.UI.WebControls.TextBox tbSensitiveIssues;
        protected System.Web.UI.WebControls.TextBox tbKeyMessage;
        protected System.Web.UI.WebControls.TextBox tbCompanyProfile;
        protected System.Web.UI.WebControls.DropDownList ddlAccountType;
        protected System.Web.UI.WebControls.TextBox tbProposalNo;
        protected System.Web.UI.WebControls.RadioButtonList rbSalesContract;
        protected System.Web.UI.WebControls.RadioButtonList rbSalesContractSigned;
        protected System.Web.UI.WebControls.RadioButtonList rbIsSensitiveIssue;
        protected System.Web.UI.WebControls.RadioButtonList rbBUHeadApproval;

        protected System.Web.UI.WebControls.TextBox tbNotSalesContractDescription;
        protected System.Web.UI.WebControls.RadioButtonList rbActivityInTrip;
        protected System.Web.UI.WebControls.RadioButtonList rbALInvitation;
        protected System.Web.UI.WebControls.TextBox tbRequestedDateFrom;
        protected System.Web.UI.WebControls.TextBox tbRequestedDateTo;
        protected System.Web.UI.WebControls.TextBox tbAlternateDateFrom;
        protected System.Web.UI.WebControls.TextBox tbAlternateDateTo;
        protected System.Web.UI.WebControls.TextBox tbTopic;
        protected System.Web.UI.WebControls.DataGrid dgALAttendee;
        protected System.Web.UI.WebControls.DataGrid dgContractInfo;
        protected System.Web.UI.WebControls.TextBox tbCustomerTeamHost;
        protected System.Web.UI.WebControls.TextBox tbCustomerOfficeTel;
        protected System.Web.UI.WebControls.TextBox tbCustomerFax;
        protected System.Web.UI.WebControls.TextBox tbCustomerEmail;
        protected System.Web.UI.WebControls.DropDownList ddlSalesBusinessUnit;
        protected System.Web.UI.WebControls.DropDownList ddlRegion;
        protected System.Web.UI.WebControls.TextBox tbPreferEntertainment;
        protected System.Web.UI.WebControls.TextBox tbEntertainmentPriceRangeFrom;
        protected System.Web.UI.WebControls.TextBox tbEntertainmentPriceRangeTo;
        protected System.Web.UI.WebControls.RadioButtonList rbGiftNeed;
        protected System.Web.UI.WebControls.TextBox tbGiftPriceRangeFrom;
        protected System.Web.UI.WebControls.TextBox tbGiftPriceRangeTo;
        protected System.Web.UI.WebControls.RadioButtonList rbReceivedGift;
        protected System.Web.UI.WebControls.RadioButtonList rbInterpreterRequired;
        protected System.Web.UI.WebControls.RadioButtonList rbSimultaneousConsecutive;
        protected System.Web.UI.WebControls.RadioButtonList rbSpecialDialect;
        protected System.Web.UI.WebControls.DropDownList ddlPayingFor;
        protected System.Web.UI.WebControls.RadioButtonList rbDirectToProvider;
        protected System.Web.UI.WebControls.TextBox tbNotDirectReason;
        protected System.Web.UI.WebControls.TextBox tbEstimateCostPerPerson;
        protected System.Web.UI.WebControls.TextBox tbReason;
        protected System.Web.UI.WebControls.RadioButtonList rbCateringService;
        protected System.Web.UI.WebControls.TextBox tbCaterServiceExplain;
        protected System.Web.UI.WebControls.DataGrid dgCustomerList;
        protected System.Web.UI.WebControls.DataGrid dgCostCenter;
        protected System.Web.UI.WebControls.TextBox tbPreferGift;
        protected System.Web.UI.WebControls.TextBox tbEstimateTotalCost;
        protected System.Web.UI.WebControls.TextBox tbRequestorName;
        protected System.Web.UI.WebControls.TextBox tbRequestOfficeTel;
        protected System.Web.UI.WebControls.TextBox tbRequestorMobile;
        protected System.Web.UI.WebControls.TextBox tbSomeoneTel;
        protected System.Web.UI.WebControls.TextBox tbDepartment;
        protected System.Web.UI.WebControls.TextBox tbOtherCountry;
        protected System.Web.UI.WebControls.RadioButtonList rbEntertainmentNeed;
        protected BEGDC.CC.Web.Control.UserSearchControl SearchStaff;
        protected System.Web.UI.WebControls.DropDownList ddlLegalEntity;

        protected System.Web.UI.WebControls.Label lbRequestorNameReadOnly;
        protected System.Web.UI.WebControls.Label lbRequestOfficeTelReadOnly;
        protected System.Web.UI.WebControls.Label lbRequestorMobileReadOnly;
        protected System.Web.UI.WebControls.Label lbSomeoneElseReadOnly;
        protected System.Web.UI.WebControls.Label lbSomeoneNameReadOnly;
        protected System.Web.UI.WebControls.Label lbSomeoneTelReadOnly;
        protected System.Web.UI.WebControls.Label lbSomeoneEmailReadOnly;
        protected System.Web.UI.WebControls.Label lbCustomerNameReadOnly;
        protected System.Web.UI.WebControls.Label lbIsFCPAReadOnly;
        protected System.Web.UI.WebControls.Label lbCustomerCountryReadOnly;
        protected System.Web.UI.WebControls.Label lbReviewGuideLineReadOnly;
        protected System.Web.UI.WebControls.Label lbPreferredLocationReadOnly;
        protected System.Web.UI.WebControls.Label lbOtherLocationReadOnly;
        //		protected System.Web.UI.WebControls.Label lbOtherCountryReadOnly;
        protected System.Web.UI.WebControls.Label lbGuestNumberReadOnly;
        protected System.Web.UI.WebControls.Label lbVisitObjectivesReadOnly;
        protected System.Web.UI.WebControls.Label lbPotentialRevenueReadOnly;
        protected System.Web.UI.WebControls.Label lbPotentialRevenueTimeReadOnly;
        protected System.Web.UI.WebControls.Label lbSaleStageReadOnly;
        protected System.Web.UI.WebControls.Label lbOutStandingRFPReadOnly;
        protected System.Web.UI.WebControls.Label lbSeneitiveIssuesReadOnly;
        protected System.Web.UI.WebControls.Label lbCompanyProfileReadOnly;
        protected System.Web.UI.WebControls.Label lbAccountTypeReadOnly;
        protected System.Web.UI.WebControls.Label lbProposalNoReadOnly;
        protected System.Web.UI.WebControls.Label lbSalesContractReadOnly;
        protected System.Web.UI.WebControls.Label lbSalesContractSignedReadOnly;
        protected System.Web.UI.WebControls.Label lbContractDateReadOnly;
        protected System.Web.UI.WebControls.Label lbContractNoReadOnly;
        protected System.Web.UI.WebControls.Label lbContractProductsReadOnly;
        protected System.Web.UI.WebControls.Label lbContractTripPurposeReadOnly;
        protected System.Web.UI.WebControls.Label lbContractQuotasReadOnly;
        protected System.Web.UI.WebControls.Label lbUnitPriceReadOnly;
        protected System.Web.UI.WebControls.Label lbReservedBudgetReadOnly;
        protected System.Web.UI.WebControls.Label lbNotSalesContractDescriptionReadOnly;
        protected System.Web.UI.WebControls.Label lbActivityInTripReadOnly;
        protected System.Web.UI.WebControls.Label lbALInvitationReadOnly;
        protected System.Web.UI.WebControls.Label lbRequestedDateFromReadOnly;
        protected System.Web.UI.WebControls.Label lbRequestedDateToReadOnly;
        protected System.Web.UI.WebControls.Label lbAlternateDateFromReadOnly;
        protected System.Web.UI.WebControls.Label lbAlternateDateToReadOnly;
        protected System.Web.UI.WebControls.Label lbTopicReadOnly;
        protected System.Web.UI.WebControls.Label lbCustomerTeamHostReadOnly;
        protected System.Web.UI.WebControls.Label lbCustomerOfficeTelReadOnly;
        protected System.Web.UI.WebControls.Label lbCustomerFaxReadOnly;
        protected System.Web.UI.WebControls.Label lbCustomerEmailReadOnly;
        protected System.Web.UI.WebControls.Label lbSalesBusinessUnitReadOnly;
        protected System.Web.UI.WebControls.Label lbRegionReadOnly;
        protected System.Web.UI.WebControls.Label lbEntertainmentNeedReadOnly;
        protected System.Web.UI.WebControls.Label lbPreferEntertainmentReadOnly;
        protected System.Web.UI.WebControls.Label lbEntertainmentPriceRangeFromReadOnly;
        protected System.Web.UI.WebControls.Label lbEntertainmentPriceRangeToReadOnly;
        protected System.Web.UI.WebControls.Label lbGiftNeedReadOnly;
        protected System.Web.UI.WebControls.Label lbPreferGiftReadOnly;
        protected System.Web.UI.WebControls.Label lbGiftPriceRangeFromReadOnly;
        protected System.Web.UI.WebControls.Label lbGiftPriceRangeToReadOnly;
        protected System.Web.UI.WebControls.Label lbReceivedGiftReadOnly;
        protected System.Web.UI.WebControls.Label lbInterpreferRequiredReadOnly;
        protected System.Web.UI.WebControls.Label lbSimultaneousConsecutiveReadOnly;
        protected System.Web.UI.WebControls.Label lbSpecialDialectReadOnly;
        protected System.Web.UI.WebControls.Label lbPayingForReadOnly;
        protected System.Web.UI.WebControls.Label lbDirectToProviderReadOnly;
        protected System.Web.UI.WebControls.Label lbNotDirectReasonReadOnly;
        protected System.Web.UI.WebControls.Label lbEstimateTotalCostReadOnly;
        protected System.Web.UI.WebControls.Label lbEstimateCostPerPersonReadOnly;
        protected System.Web.UI.WebControls.Label lbReasonReadOnly;
        protected System.Web.UI.WebControls.Label lbCateringServiceReadOnly;
        protected System.Web.UI.WebControls.Label lbCaterServiceExplainReadOnly;
        protected System.Web.UI.WebControls.Label lbLegalEntity;
        protected System.Web.UI.WebControls.Label lbBUHeadApprovalReadOnly;
        protected System.Web.UI.WebControls.TextBox tbOperationFlag;
        protected System.Web.UI.WebControls.TextBox tbComment;

        protected System.Web.UI.WebControls.Label lbAccount;
        protected System.Web.UI.WebControls.Label lbContractSum;
        protected System.Web.UI.WebControls.Label lbCostSum;
        protected System.Web.UI.WebControls.Label lbAppNo;
        protected System.Web.UI.WebControls.Label lbSummaryReadOnly;
        protected System.Web.UI.WebControls.Button CustomerPaneImg;
        protected System.Web.UI.WebControls.Button ALPaneImg;
        protected System.Web.UI.WebControls.Button CostCenterPaneImg;
        protected System.Web.UI.HtmlControls.HtmlTableRow tr_Title;
        protected System.Web.UI.HtmlControls.HtmlTableRow tr_Button;
        protected System.Web.UI.HtmlControls.HtmlTableRow tr_knowledge;
        protected System.Web.UI.WebControls.TextBox Ctl_ArrivalDate;
        protected System.Web.UI.WebControls.Literal litScript;
        protected System.Web.UI.WebControls.RadioButtonList rbKeyMessage;
        protected System.Web.UI.WebControls.Label lbKeyMessage;
        protected System.Web.UI.WebControls.Label lbKeyMessageReadOnly;

        protected System.Web.UI.HtmlControls.HtmlGenericControl img2;
        protected System.Web.UI.HtmlControls.HtmlGenericControl img3;
        protected System.Web.UI.HtmlControls.HtmlGenericControl img4;
        protected System.Web.UI.HtmlControls.HtmlGenericControl img5;
        protected System.Web.UI.WebControls.Button ConrtractInfoPane;
        protected System.Web.UI.WebControls.DataGrid Btn_ContractDelete;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span1;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span2;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span3;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span4;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span5;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span6;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span7;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span8;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span9;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span10;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span11;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span12;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span13;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span14;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span15;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span16;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span17;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span18;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span19;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span20;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span21;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span22;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span23;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span24;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span25;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span26;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span27;
        protected System.Web.UI.HtmlControls.HtmlGenericControl span28;

        protected System.Web.UI.WebControls.TextBox tbTravel;
        protected System.Web.UI.WebControls.TextBox tbCustomerCount;
        protected System.Web.UI.WebControls.Label lbTravelReadOnly;
        protected System.Web.UI.WebControls.TextBox tbHRID;
        protected System.Web.UI.WebControls.TextBox tbSomeoneMobile;
        protected System.Web.UI.WebControls.Label lbSomeoneHRIDReadOnly;
        protected System.Web.UI.WebControls.Label lbSomeoneMobileReadOnly;
        protected System.Web.UI.WebControls.TextBox tbReceivedGift;
        protected System.Web.UI.WebControls.Label lbReceivedGiftDescriptionReadOnly;
        protected System.Web.UI.WebControls.Label lbEZVisitNoReadOnly;
        protected System.Web.UI.WebControls.Label lbLGDNoReadOnly;
        protected BEGDC.CC.Web.Common.StampCtrl stampCtrl1;
        protected BEGDC.CC.Web.UserControls.EBDCV.CloseCtl closectl1;

        public BEGDC.CC.Web.UserControls.CV.CVPrintCtrl cvPrintCtrl;
        protected ASB.CC.Web.UserControls.RequesterInfoControl RequesterInfoControl;


        private bool _isReadOnly = false;
        public bool isReadOnly
        {
            set
            {
                _isReadOnly = value;
            }
            get
            {
                return _isReadOnly;
            }
        }
        private int CustomerID
        {
            set
            {
                ViewState["customerID"] = value;
            }
            get
            {
                if (ViewState["customerID"] == null)
                    return 0;
                return Convert.ToInt32(ViewState["customerID"]);
            }
        }
        private int BusinessID
        {
            set
            {
                ViewState["businessID"] = value;
            }
            get
            {
                if (ViewState["businessID"] == null)
                    return 0;
                return Convert.ToInt32(ViewState["businessID"]);
            }
        }
        private int TopicID
        {
            set
            {
                ViewState["topicID"] = value;
            }
            get
            {
                if (ViewState["topicID"] == null)
                    return 0;
                return Convert.ToInt32(ViewState["topicID"]);
            }
        }
        private int SalesTeamID
        {
            set
            {
                ViewState["salesTeamID"] = value;
            }
            get
            {
                if (ViewState["salesTeamID"] == null)
                    return 0;
                return Convert.ToInt32(ViewState["salesTeamID"]);
            }
        }
        private int LogistID
        {
            set
            {
                ViewState["logistID"] = value;
            }
            get
            {
                if (ViewState["logistID"] == null)
                    return 0;
                return Convert.ToInt32(ViewState["logistID"]);
            }
        }
        private int PaymentID
        {
            set
            {
                ViewState["paymentID"] = value;
            }
            get
            {
                if (ViewState["paymentID"] == null)
                    return 0;
                return Convert.ToInt32(ViewState["paymentID"]);
            }
        }

        #endregion

        #region variable define
        private bool IsQuery
        {
            get
            {
                string state = this.Request.QueryString["State"];
                if (state == null) return false;
                return state == SysDicItem.ProjectStatusFlag.QUERY;
            }
        }
        private bool IsView
        {
            get
            {
                string state = this.Request.QueryString["State"];
                if (state == null) return false;
                if (state == SysDicItem.ProjectStatusFlag.View || state == SysDicItem.ProjectStatusFlag.CANCEL
                    || state == SysDicItem.ProjectStatusFlag.Pending || state == SysDicItem.ProjectStatusFlag.End
                    || state == SysDicItem.ProjectStatusFlag.Participation || state == SysDicItem.ProjectStatusFlag.Closed)
                    return true;
                else
                    return false;
            }
        }
        private bool NeedSSMEApprove
        {
            get
            {
                if (this.ViewState["NeedSSMEApprove"] == null)
                    return false;
                return (bool)this.ViewState["NeedSSMEApprove"];
            }
            set { this.ViewState["NeedSSMEApprove"] = value; }
        }
        private string _step = string.Empty;
        protected string Step
        {
            get
            {
                IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;
                FlowInstance flowInstance = queryService.QueryFlowInstance(this.AppID);
                if (flowInstance == null)
                    return WorkTransition.Draft;
                else
                {
                    _step = flowInstance.CurrentStep.StepCode;
                    return flowInstance.CurrentActiveStep.StepCode;
                }
            }
        }
        protected string ApplicationNo
        {
            get
            {
                if (this.ViewState["ApplicationNo"] == null)
                    return string.Empty;
                return this.ViewState["ApplicationNo"].ToString();
            }
            set { this.ViewState["ApplicationNo"] = value; }
        }

        protected System.Web.UI.WebControls.TextBox Textbox1;
        protected System.Web.UI.WebControls.Label lbIsSensitiveIssue;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hiddenScrollHight;
        protected System.Web.UI.WebControls.Label lblLegalEntity;
        protected System.Web.UI.WebControls.Label lbDepartmentReadOnly;
        protected System.Web.UI.WebControls.Label lbIsSSMEReadOnly;
        protected System.Web.UI.WebControls.DropDownList ddlCostCenter;
        protected System.Web.UI.WebControls.Label lbCostCenterReadOnly;
        protected System.Web.UI.WebControls.DropDownList ddlDepartment;
        protected System.Web.UI.HtmlControls.HtmlTableRow TR_CounselApprovalTitle;
        protected System.Web.UI.HtmlControls.HtmlTableRow TR_CounselApproval;
        protected System.Web.UI.WebControls.RadioButtonList rbHotelRequired;
        protected System.Web.UI.WebControls.Label lbHotelRequiredReadOnly;
        protected System.Web.UI.WebControls.TextBox tbHotelPreferences;
        protected System.Web.UI.WebControls.Label lbHotelPreferencesReadOnly;
        protected System.Web.UI.WebControls.TextBox tbDatesRequiredFrom;
        protected System.Web.UI.WebControls.Label lbDatesRequiredFromReadOnly;
        protected System.Web.UI.WebControls.TextBox tbDatesRequiredTo;
        protected System.Web.UI.WebControls.Label lbDatesRequiredToReadOnly;
        protected System.Web.UI.WebControls.RadioButtonList rbTransportationRequired;
        protected System.Web.UI.WebControls.Label lbTransportationRequiredReadOnly;
        protected System.Web.UI.WebControls.RadioButtonList rbIsEBD;
        protected System.Web.UI.WebControls.Label lbOtherCountryReadOnly;
        #endregion

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (cvPrintCtrl != null)
            {
                cvPrintCtrl.ProcessType = WorkflowTypes.EBDCV;
            }
            if (!Page.IsPostBack)
            {
                Session[SessionFlag.AccompanySessionEZ] = null;
                Session[SessionFlag.CustomerSessionEZ] = null;
                Session[SessionFlag.ContractInfo] = null;
                Session[SessionFlag.CostCenter] = null;
                Session[SessionFlag.AccompanySession] = null;
                Session[SessionFlag.CustomerSession] = null;
                Session[SessionFlag.MeetingMinutesAttendee] = null;

                base.PreInitForm();
                InitialDropDownList();
                InitialNumberCheck();
                BindApplication();

            }
            else
            {
                BindCustomerAttendee();
                BindALAttendee();
                BindCostCenter();
                BindContractInfo();
            }
            this.closectl1.BindCostCenter();
            ButtonStatusSetting();

            if (this.Access != null)
                ShowPanel(this.Access.IsReadOnly || this.IsView);
            else
                ShowPanel(this.isReadOnly || this.IsView);
            this.RequesterInfoControl.isReadOnly = this.isReadOnly;
            if (this.Step == WorkTransition.EBDCV_Close || this.Step == WorkTransition.End)
                this.closectl1.Visible = true;
            else
                this.closectl1.Visible = false;

            if (this.Step == WorkTransition.EBDCV_ReApply || (this.IsQuery && _step != WorkTransition.EBDCV_Assignment))
                this.DisableSSME();
        }

        private void InitialNumberCheck()
        {
            this.tbEntertainmentPriceRangeFrom.Attributes["onkeypress"] = "javascript: return CheckNum('tbEntertainmentPriceRangeFrom',event);";
            this.tbEntertainmentPriceRangeTo.Attributes["onkeypress"] = "javascript: return CheckNum('tbEntertainmentPriceRangeTo',event);";
            this.tbGiftPriceRangeFrom.Attributes["onkeypress"] = "javascript: return CheckNum('tbGiftPriceRangeFrom',event);";
            this.tbGiftPriceRangeTo.Attributes["onkeypress"] = "javascript: return CheckNum('tbGiftPriceRangeTo',event);";
        }

        private void ShowPanel(bool isReadOnly)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script>");
            if (isReadOnly)
            {
                sb.Append("_showSSMEPart(" + this.rbIsEBD.SelectedValue + ");");
                sb.Append("_showpart2(" + this.rbSomeoneElse.SelectedValue + ");");
                sb.Append("_ShowSensitiveIssue(" + this.rbIsSensitiveIssue.SelectedValue + ");");
                sb.Append("_ShowGiftPart(" + this.rbGiftNeed.SelectedValue + ");");
                sb.Append("_ShowReceivedGiftPart(" + this.rbReceivedGift.SelectedValue + ");");
                sb.Append("_ShowEnterment(" + this.rbEntertainmentNeed.SelectedValue + ");");
                sb.Append("_ShowContractPart(" + this.rbSalesContract.SelectedValue + ");");
                if (this.rbSalesContract.SelectedValue == "1")
                    sb.Append("_ShowContractRowPart(" + this.rbSalesContractSigned.SelectedValue + ");");
                sb.Append("_ShowCater(" + this.rbCateringService.SelectedValue + ");");
                sb.Append("_ShowKeyMessage(" + this.rbKeyMessage.SelectedValue + ");");
                sb.Append("_ShowPayment(" + this.rbDirectToProvider.SelectedValue + ");");
                sb.Append("_ShowInterpreterPart(" + this.rbInterpreterRequired.SelectedValue + ");");
            }
            else
            {
                sb.Append("showSSMEPart();");
                sb.Append("showpart2();");
                sb.Append("ShowSensitiveIssue();");
                sb.Append("ShowGiftPart();");
                sb.Append("ShowReceivedGiftPart();");
                sb.Append("ShowEnterment();");
                sb.Append("ShowContractPart();");
                //				sb.Append("ShowContractRowPart();");
                sb.Append("ShowCater();");
                sb.Append("ShowKeyMessage();");
                sb.Append("ShowPayment();");
                sb.Append("ShowInterpreterPart();");
            }
            sb.Append("</script>");
            Page.RegisterStartupScript("EZCtrlForCO_Startup", sb.ToString());
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        ///		Required method for Designer support - do not modify
        ///		the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.dgContractInfo.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgContractInfo_DeleteCommand);
            this.dgContractInfo.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgContractInfo_ItemDataBound);
            this.dgCustomerList.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCustomerList_DeleteCommand);
            this.dgCustomerList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgCustomerList_ItemDataBound);
            this.dgALAttendee.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgALAttendee_DeleteCommand);
            this.dgALAttendee.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgALAttendee_ItemDataBound);
            this.dgCostCenter.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCostCenter_DeleteCommand);
            this.dgCostCenter.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgCostCenter_ItemDataBound);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void InitialDropDownList()
        {
            WebUtility.BuildDropDown(ddlPotentialRevenueTime, BEGDC.CC.BL.Common.DicType.POTENTIAL_REVENUE_TIMEFRAME, false, false);
            WebUtility.BuildDropDown(ddlSaleStage, BEGDC.CC.BL.Common.DicType.SALES_STAGE, false, false);
            WebUtility.BuildDropDown(ddlAccountType, BEGDC.CC.BL.Common.DicType.ACCOUNT_TYPE, false, false);
            WebUtility.BuildDropDown(ddlSalesBusinessUnit, BEGDC.CC.BL.Common.DicType.SALES_BUSINESS_UNIT_OCO, false, false);
            WebUtility.BuildDropDown(ddlRegion, BEGDC.CC.BL.Common.DicType.REGION_OCO, false, false);
            WebUtility.BuildDropDown(ddlPayingFor, BEGDC.CC.BL.Common.DicType.PAYER, false, false);
            WebUtility.BuildCheckBoxList(this.cblPreferredLocation, BEGDC.CC.BL.Common.DicType.OCOOversea);
            WebUtility.BuildDropDown(this.ddlDepartment, BEGDC.CC.BL.Common.DicType.NONSSEMDepartment, false, false);
            WebUtility.BuildDropDown(this.ddlCostCenter, BEGDC.CC.BL.Common.DicType.CostCenter, false, false);

            BEGDC.CC.BL.Common.Query.IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as BEGDC.CC.BL.Common.Query.IQuery;

            //init legal entity
            this.ddlLegalEntity.DataSource = queryService.GetAllLegalEntity();
            this.ddlLegalEntity.DataTextField = "LegalEntityName";
            this.ddlLegalEntity.DataValueField = "LegalEntityID";
            this.ddlLegalEntity.DataBind();
        }

        private void BindApplication()
        {
            this.LoadApplication();
            //this.tbRequestorName.Text = HttpContext.Current.User.Identity.Name;
            Employee emp = this.GetUser(HttpContext.Current.User.Identity.Name);
            this.tbDepartment.Text = emp.Department.Id.ToString() + "_" + emp.Department.DepartmentType.DicItemKey;

            if (this.AppID == 0)
            {
                BindCustomerAttendee();
                BindALAttendee();
                BindCostCenter();
                BindContractInfo();
                this.tr_knowledge.Visible = false;
                return;
            }
            IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
            CustomerInfo customer = queryService.GetCustomerInfo(this.AppID);
            BusinessPurpose business = queryService.GetBusinessPurposeInfo(this.AppID);
            Topic topic = queryService.GetTopicInfo(this.AppID);
            SalesTeamInfo salesTeam = queryService.GetSalesTeamInfo(this.AppID);
            LogisticalInfo logist = queryService.GetLogisticalInfo(this.AppID);
            PaymentInfo payment = queryService.GetPaymentInfo(this.AppID);
            DataTable visitingSite = queryService.GetVisitingSite(this.AppID);
            this.CustomerID = customer.Id;
            this.BusinessID = business.Id;
            this.TopicID = topic.Id;
            this.SalesTeamID = salesTeam.Id;
            this.LogistID = logist.Id;
            this.PaymentID = payment.Id;
            BindApplicationData(visitingSite);
            BindCustomerInfoData(customer);
            BindBusinessPurposeData(business);
            BindTopicData(topic);
            BindSalesTeamData(salesTeam);
            BindLogisticalData(logist);
            BindPaymentData(payment);
            BindCustomerAttendee();
            BindALAttendee();
            BindCostCenter();
            BindContractInfo();

        }

        private void BindApplicationData(DataTable site)
        {
            //this.tbRequestorName.Text = this.Application.RequesterNameEN;
            //			Employee emp = this.GetUser(this.Application.RequesterNameEN);
            //			this.lbDepartmentReadOnly.Text = emp.Department.DepartmentCode;
            this.ddlLegalEntity.SelectedValue = this.Application.LegalEntity.Id.ToString();
            //			this.tbDepartment.Text = emp.Department.Id.ToString() + "_" + emp.Department.DepartmentType.DicItemKey;

            //this.tbRequestorName.Text = this.Application.RequesterNameEN;
            //this.tbRequestOfficeTel.Text = this.Application.RequesterOfficeTel;
            //this.tbRequestorMobile.Text = this.Application.RequesterMobile;
            this.rbReviewGuideLine.SelectedValue = this.Application.IsReviewedGuideline ? "1" : "0";
            this.NeedSSMEApprove = this.Application.NeedEVPApproval;

            if (this.Application.Summary + string.Empty != string.Empty)
                this.lbSummaryReadOnly.Text = this.Application.Summary;
            else
                this.tr_knowledge.Visible = false;
            if (this.Application.RequestedDateFrom != null)
                this.tbRequestedDateFrom.Text = ((DateTime)this.Application.RequestedDateFrom).ToString("MM/dd/yyyy");
            if (this.Application.RequestedDateTo != null)
                this.tbRequestedDateTo.Text = ((DateTime)this.Application.RequestedDateTo).ToString("MM/dd/yyyy");
            if (this.Application.AlternateDateFrom != null)
                this.tbAlternateDateFrom.Text = ((DateTime)this.Application.AlternateDateFrom).ToString("MM/dd/yyyy");
            if (this.Application.AlternateDateTo != null)
                this.tbAlternateDateTo.Text = ((DateTime)this.Application.AlternateDateTo).ToString("MM/dd/yyyy");
            this.ApplicationNo = this.Application.AppNo;
            if (this.ApplicationNo != string.Empty)
                this.lbAppNo.Text = "Application No: " + this.ApplicationNo;
            this.rbIsEBD.SelectedValue = this.Application.IsSSME ? "1" : "0";
            if (this.Application.IsSSME)
                this.ddlCostCenter.SelectedValue = this.Application.CostCenterCode.Id.ToString();
            else
                this.ddlDepartment.SelectedValue = this.Application.DepartmentType.Id.ToString();

            this.rbSomeoneElse.SelectedValue = this.Application.ApplyForSomeoneElse ? "1" : "0";
            this.rbBUHeadApproval.SelectedValue = this.Application.BUHeadApproved ? "1" : "0";
            if (this.Application.ApplyForSomeoneElse)
            {
                this.SearchStaff.EmployeeName = this.Application.SomeoneElseNameEN;
                if (this.Application.SomeoneElseNo != null)
                    this.SearchStaff.EmployeeID = this.Application.SomeoneElseNo.Id;
                this.tbSomeoneTel.Text = this.Application.SomeoneElseTel;
                this.tbSomeoneEmail.Text = this.Application.SomeoneElseEmail;
                this.tbHRID.Text = this.Application.SomeoneElseHRID;
                this.tbSomeoneMobile.Text = this.Application.SomeoneElseMobil;
            }
            if (site != null && site.Rows.Count > 0)
            {
                for (int i = 0; i < site.Rows.Count; i++)
                    for (int j = 0; j < this.cblPreferredLocation.Items.Count; j++)
                    {
                        if (site.Rows[i]["DicItemID"].ToString() == cblPreferredLocation.Items[j].Value)
                            cblPreferredLocation.Items[j].Selected = true;
                    }
            }
            this.tbOtherCountry.Text = this.Application.OtherCountry;
        }

        private void BindCustomerInfoData(CustomerInfo customer)
        {
            if (customer != null)
            {
                this.tbCustomerName.Text = customer.Company;
                this.rbIsFCPA.SelectedValue = customer.IsFCPA ? "1" : "0";
                this.tbCustomerCountry.Text = customer.Country;
                this.lbGuestNumberReadOnly.Text = customer.NumberOfPerson;
                this.tbVisitObjectives.Text = customer.VisitObjective;
                this.tbPotentialRevenue.Text = customer.DecryptedRevenuePotential.ToString();
                this.ddlPotentialRevenueTime.SelectedValue = customer.PotentialRevenueTimeframe.ToString();
                this.ddlSaleStage.SelectedValue = customer.SalesStage.ToString();
                this.rbOutStandingRFP.SelectedValue = customer.IsInRFP ? "1" : "0";
                this.tbSensitiveIssues.Text = customer.IsThereSensitiveIssue;
                this.rbKeyMessage.SelectedValue = customer.IsKeyMessage ? "1" : "0";
                this.tbKeyMessage.Text = customer.IsThereKeyMessage;
                this.tbCompanyProfile.Text = customer.CompanyProfile;
                this.ddlAccountType.SelectedValue = customer.AccountType.Id.ToString();
                this.tbProposalNo.Text = customer.ProposalNo;
                this.tbSensitiveIssues.Text = customer.IsThereSensitiveIssue;
                this.rbIsSensitiveIssue.SelectedValue = customer.IsSensitiveIssue ? "1" : "0";
            }
        }

        private void BindBusinessPurposeData(BusinessPurpose business)
        {
            if (business != null)
            {
                this.rbSalesContract.SelectedValue = business.IsInSalesContract ? "1" : "0";
                this.rbSalesContractSigned.SelectedValue = business.IsContractSigned ? "1" : "0";
                this.rbActivityInTrip.SelectedValue = business.RecreationalActivity ? "1" : "0";
                this.rbALInvitation.SelectedValue = business.IsNeedInvitationLetter ? "1" : "0";
                this.tbNotSalesContractDescription.Text = business.Opportunities;
            }
        }

        private void BindTopicData(Topic topic)
        {
            if (topic != null)
            {
                this.tbTopic.Text = topic.TopicName;
            }
        }

        private void BindSalesTeamData(SalesTeamInfo salesTeam)
        {
            if (salesTeam != null)
            {
                this.tbCustomerTeamHost.Text = salesTeam.HostNameEN;
                this.tbCustomerOfficeTel.Text = salesTeam.OfficeTel;
                this.tbCustomerFax.Text = salesTeam.OfficeFax;
                this.tbCustomerEmail.Text = salesTeam.Email;
                this.ddlSalesBusinessUnit.SelectedValue = salesTeam.SalesBusinessUnit;
                this.ddlRegion.SelectedValue = salesTeam.Region;
            }
        }

        private void BindLogisticalData(LogisticalInfo logist)
        {
            if (logist != null)
            {
                this.rbEntertainmentNeed.SelectedValue = logist.IsNeedEntertainment ? "1" : "0";
                this.tbPreferEntertainment.Text = logist.EntertainmentPreference;
                this.tbEntertainmentPriceRangeFrom.Text = logist.DecryptedEntertainmentPriceFrom.ToString();
                if (logist.DecryptedEntertainmentPriceTo.ToString() != "0")
                    this.tbEntertainmentPriceRangeTo.Text = logist.DecryptedEntertainmentPriceTo.ToString();
                this.rbGiftNeed.SelectedValue = logist.IsNeedGift ? "1" : "0";
                this.tbPreferGift.Text = logist.GiftPreference;
                this.tbGiftPriceRangeFrom.Text = logist.DecryptedGiftPriceFrom.ToString();
                if (logist.DecryptedGiftPriceTo.ToString() != "0")
                    this.tbGiftPriceRangeTo.Text = logist.DecryptedGiftPriceTo.ToString();
                this.rbReceivedGift.SelectedValue = logist.IsReceivedALGiftBefore ? "1" : "0";
                this.rbInterpreterRequired.SelectedValue = logist.IsNeedInterpreter ? "1" : "0";
                this.rbSimultaneousConsecutive.SelectedValue = logist.InterpretionType.ToString();
                this.rbSpecialDialect.SelectedValue = logist.SpecialDialect;
                this.rbCateringService.SelectedValue = logist.IsNeedCatering ? "1" : "0";
                this.tbCaterServiceExplain.Text = logist.CateringDescription;
                this.tbTravel.Text = logist.TravelAgency;
                this.tbReceivedGift.Text = logist.ReceivedGiftDetails;
            }
        }

        private void BindPaymentData(PaymentInfo payment)
        {
            if (payment != null)
            {
                this.ddlPayingFor.SelectedValue = payment.Payer.ToString();
                this.rbDirectToProvider.SelectedValue = payment.IsPayServiceProvider ? "1" : "0";
                this.tbNotDirectReason.Text = payment.NotDirectPayReasons;
                this.tbEstimateTotalCost.Text = payment.DecryptedEstimatedCustomerTotalCost.ToString();
                this.tbEstimateCostPerPerson.Text = payment.DecryptedEstimateCustomerdIndividualCost.ToString();
                this.tbReason.Text = payment.CustomerPerdiem;
            }
        }

        private void BindCustomerAttendee()
        {
            DataTable CustomerDataTable = null;
            object SessCustomerAttendee = Session[SessionFlag.CustomerSessionEZ];
            if (SessCustomerAttendee != null)
            {
                CustomerDataTable = (DataTable)SessCustomerAttendee;
                try
                {
                    this.dgCustomerList.DataSource = this.SetRowID(CustomerDataTable);
                    this.dgCustomerList.DataBind();
                }
                catch
                {
                    SessCustomerAttendee = null;
                }
            }
            if (SessCustomerAttendee == null)
            {
                IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                if (this.CustomerID > 0)
                {
                    CustomerDataTable = queryService.GetCustomerAttendeeList(this.CustomerID);
                }

                if (CustomerDataTable != null && CustomerDataTable.Rows.Count > 0)
                {
                    if (!CustomerDataTable.Columns.Contains("AttendeeCount"))
                    {
                        CustomerDataTable.Columns.Add(new DataColumn("AttendeeCount", typeof(System.Int32)));

                        foreach (DataRow dr in CustomerDataTable.Rows)
                        {
                            dr["AttendeeCount"] = queryService.GetCustomerAttendeeCountForOversea(dr["Name"].ToString(), dr["Company"].ToString());
                        }
                    }

                    //送礼次数
                    if (!CustomerDataTable.Columns.Contains("GiftCount"))
                    {
                        CustomerDataTable.Columns.Add(new DataColumn("GiftCount", typeof(System.Int32)));

                        foreach (DataRow dr in CustomerDataTable.Rows)
                        {
                            dr["GiftCount"] = queryService.GetGiftCount(dr["Name"].ToString(), dr["Company"].ToString());
                        }
                    }

                    //娱乐次数
                    if (!CustomerDataTable.Columns.Contains("EntertainmentCount"))
                    {
                        CustomerDataTable.Columns.Add(new DataColumn("EntertainmentCount", typeof(System.Int32)));

                        foreach (DataRow dr in CustomerDataTable.Rows)
                        {
                            dr["EntertainmentCount"] = queryService.GetEntertainmentCount(dr["Name"].ToString(), dr["Company"].ToString());
                        }
                    }

                    Session[SessionFlag.CustomerSessionEZ] = CustomerDataTable;
                }
                else
                {
                    CustomerDataTable = new DataTable();
                    CustomerDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Name", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Company", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Title", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("NameCN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("CompanyEN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("TitleEN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Responsibility", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Affects", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("ResponsibilityID", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("AffectsID", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Remark", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("IsExisted", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("AttendeeCount", typeof(System.Int32)));
                    Session[SessionFlag.CustomerSessionEZ] = CustomerDataTable;
                }
            }
            if (CustomerDataTable.Select("IsExisted='" + BEGDC.CC.BL.Common.CISFlag.NotExisted + "'").Length > 0)
            {
                this.Lb_CISWarning.Visible = true;
            }
            else
            {
                this.Lb_CISWarning.Visible = false;
            }
            this.dgCustomerList.DataSource = this.SetRowID(CustomerDataTable);
            this.dgCustomerList.DataBind();
            this.lbGuestNumberReadOnly.Text = CustomerDataTable.Rows.Count.ToString();

            // Auto calculate cost per person
            this.litScript.Visible = true;
            this.litScript.Text = string.Empty;
            this.litScript.Text = "<script>SetCustomerCount(" + CustomerDataTable.Rows.Count.ToString() + ");CalculateCostPerPerson();</script>";

        }

        private void BindALAttendee()
        {
            DataTable AccompanyingAttendee = null;
            if (Session[SessionFlag.AccompanySessionEZ] != null)
            {
                AccompanyingAttendee = (DataTable)Session[SessionFlag.AccompanySessionEZ];
            }
            else
            {
                if (this.AppID > 0)
                {
                    ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
                    AccompanyingAttendee = crService.GetAccompanyingAttendeeList(this.AppID);
                }
                if (AccompanyingAttendee == null || AccompanyingAttendee.Rows.Count == 0)
                {
                    AccompanyingAttendee = new DataTable();
                    AccompanyingAttendee.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    AccompanyingAttendee.Columns.Add(new DataColumn("EmployeeId", typeof(System.String)));
                    AccompanyingAttendee.Columns.Add(new DataColumn("Name", typeof(System.String)));
                    AccompanyingAttendee.Columns.Add(new DataColumn("Title", typeof(System.String)));
                }
                Session[SessionFlag.AccompanySessionEZ] = AccompanyingAttendee;
            }
            this.dgALAttendee.DataSource = this.SetRowID(AccompanyingAttendee);
            this.dgALAttendee.DataBind();
        }

        private void BindCostCenter()
        {
            DataTable CostCenter = null;
            if (Session[SessionFlag.CostCenter] != null)
            {
                CostCenter = (DataTable)Session[SessionFlag.CostCenter];
            }
            else
            {
                if (this.PaymentID > 0)
                {
                    IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                    CostCenter = queryService.GetCostCenter(this.PaymentID);
                }
                if (CostCenter == null || CostCenter.Rows.Count == 0)
                {
                    CostCenter = new DataTable();
                    CostCenter.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    CostCenter.Columns.Add(new DataColumn("CostCenterCode", typeof(System.String)));
                    CostCenter.Columns.Add(new DataColumn("Cost", typeof(System.String)));
                    CostCenter.Columns.Add(new DataColumn("ActualCost", typeof(System.String)));
                    CostCenter.Columns.Add(new DataColumn("ActualTransferCost", typeof(System.String)));
                }
                Session[SessionFlag.CostCenter] = CostCenter;
            }
            this.dgCostCenter.DataSource = this.SetRowID(CostCenter);
            this.dgCostCenter.DataBind();

            this.lbCostSum.Text = this.CalculateCostSum();
        }

        private void BindContractInfo()
        {
            DataTable ContractInfo = null;
            if (Session[SessionFlag.ContractInfo] != null)
            {
                ContractInfo = (DataTable)Session[SessionFlag.ContractInfo];
            }
            else
            {
                if (this.AppID > 0)
                {
                    IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                    ContractInfo = SetRowID(queryService.QueryContractInfoByAppId(this.AppID));
                }
                if (ContractInfo == null || ContractInfo.Rows.Count == 0)
                {
                    ContractInfo = new DataTable();
                    ContractInfo.Columns.Add(new DataColumn("RowId", typeof(System.String)));
                    ContractInfo.Columns.Add(new DataColumn("DateOfContract", typeof(System.DateTime)));
                    ContractInfo.Columns.Add(new DataColumn("ContractNo", typeof(System.String)));
                    ContractInfo.Columns.Add(new DataColumn("ProducstSold", typeof(System.String)));
                    ContractInfo.Columns.Add(new DataColumn("VisitPurposeInContract", typeof(System.String)));
                    ContractInfo.Columns.Add(new DataColumn("Quotas", typeof(System.Int32)));
                    ContractInfo.Columns.Add(new DataColumn("UnitPrice", typeof(System.Decimal)));
                    ContractInfo.Columns.Add(new DataColumn("Budget", typeof(System.Decimal)));
                }
                Session[SessionFlag.ContractInfo] = ContractInfo;
            }
            this.dgContractInfo.DataSource = this.SetRowID(ContractInfo);
            this.dgContractInfo.DataBind();

            this.lbContractSum.Text = CalculateSum();
        }

        private DataTable SetRowID(DataTable table)
        {
            if (table != null && table.Rows.Count > 0)
                for (int i = 1; i <= table.Rows.Count; i++)
                {
                    table.Rows[i - 1][0] = i.ToString();
                }
            return table;
        }

        private void BindReadOnlyStatus()
        {
            this.ALPaneImg.Visible = false;
            this.CustomerPaneImg.Visible = false;
            this.CostCenterPaneImg.Visible = false;
            this.ConrtractInfoPane.Visible = false;
            this.img2.Visible = false;
            this.img3.Visible = false;
            this.img3.Visible = false;
            this.img4.Visible = false;
            this.img5.Visible = false;
            this.span1.Visible = false;
            this.span2.Visible = false;
            this.span3.Visible = false;
            this.span4.Visible = false;
            this.span5.Visible = false;
            this.span6.Visible = false;
            this.span7.Visible = false;
            //this.span8.Visible = false;
            this.span9.Visible = false;
            this.span10.Visible = false;
            this.span11.Visible = false;
            this.span12.Visible = false;
            this.span13.Visible = false;
            this.span14.Visible = false;
            this.span15.Visible = false;
            this.span16.Visible = false;
            this.span17.Visible = false;
            this.span18.Visible = false;
            this.span19.Visible = false;
            this.span20.Visible = false;
            this.span21.Visible = false;
            this.span22.Visible = false;
            this.span23.Visible = false;
            this.span24.Visible = false;
            this.span25.Visible = false;
            this.span26.Visible = false;
            this.span27.Visible = false;
            this.span28.Visible = false;

            // Application
            //this.tbRequestorName.Visible = false;
            //this.lbRequestorNameReadOnly.Text = this.tbRequestorName.Text;
            //this.tbRequestOfficeTel.Visible = false;
            //this.lbRequestOfficeTelReadOnly.Text = this.tbRequestOfficeTel.Text;
            //this.tbRequestorMobile.Visible = false;
            //this.lbRequestorMobileReadOnly.Text = this.tbRequestorMobile.Text;
            this.rbReviewGuideLine.Visible = false;
            this.lbReviewGuideLineReadOnly.Text = this.rbReviewGuideLine.SelectedItem.Text;

            this.tbRequestedDateFrom.Visible = false;
            this.lbRequestedDateFromReadOnly.Text = this.tbRequestedDateFrom.Text;
            this.tbRequestedDateTo.Visible = false;
            this.lbRequestedDateToReadOnly.Text = this.tbRequestedDateTo.Text;
            this.tbAlternateDateFrom.Visible = false;
            this.lbAlternateDateFromReadOnly.Text = this.tbAlternateDateFrom.Text;
            this.tbAlternateDateTo.Visible = false;
            this.lbAlternateDateToReadOnly.Text = this.tbAlternateDateTo.Text;
            this.rbSomeoneElse.Visible = false;
            this.lbSomeoneElseReadOnly.Text = this.rbSomeoneElse.SelectedItem.Text;
            this.SearchStaff.Visible = false;
            this.lbSomeoneNameReadOnly.Text = this.SearchStaff.EmployeeName;
            this.tbSomeoneTel.Visible = false;
            this.lbSomeoneTelReadOnly.Text = this.tbSomeoneTel.Text;
            this.tbSomeoneEmail.Visible = false;
            this.lbSomeoneEmailReadOnly.Text = this.tbSomeoneEmail.Text;
            this.tbHRID.Visible = false;
            this.lbSomeoneHRIDReadOnly.Text = this.tbHRID.Text;
            this.tbSomeoneMobile.Visible = false;
            this.lbSomeoneMobileReadOnly.Text = this.tbSomeoneMobile.Text;
            this.cblPreferredLocation.Visible = false;
            for (int i = 0; i < this.cblPreferredLocation.Items.Count; i++)
                if (cblPreferredLocation.Items[i].Selected)
                    this.lbPreferredLocationReadOnly.Text += cblPreferredLocation.Items[i].Text + ",";
            string temp = this.lbPreferredLocationReadOnly.Text;
            if (temp != string.Empty)
                this.lbPreferredLocationReadOnly.Text = temp.Substring(0, temp.Length - 1);

            if (this.Application.EZVisitReqNo != string.Empty)
                this.lbEZVisitNoReadOnly.Text = "EZVisitNo: " + this.Application.EZVisitReqNo;
            if (this.Application.LGDNo != string.Empty)
                this.lbLGDNoReadOnly.Text = "LGD No: " + this.Application.LGDNo;
            this.ddlLegalEntity.Visible = false;
            this.lbLegalEntity.Text = this.ddlLegalEntity.SelectedItem.Text;
            this.rbBUHeadApproval.Visible = false;
            this.lbBUHeadApprovalReadOnly.Text = this.rbBUHeadApproval.SelectedItem.Text;
            this.rbIsEBD.Visible = false;
            this.lbIsSSMEReadOnly.Text = "&nbsp;&nbsp;" + this.rbIsEBD.SelectedItem.Text;
            this.ddlDepartment.Visible = false;
            this.lbDepartmentReadOnly.Text = this.ddlDepartment.SelectedItem.Text;
            this.ddlCostCenter.Visible = false;
            this.lbCostCenterReadOnly.Text = this.ddlCostCenter.SelectedItem.Text;
            this.rbKeyMessage.Visible = false;
            this.lbKeyMessage.Text = this.rbKeyMessage.SelectedItem.Text;
            this.lbKeyMessageReadOnly.Text = this.tbKeyMessage.Text;

            // Customer
            this.tbCustomerName.Visible = false;
            this.lbCustomerNameReadOnly.Text = this.tbCustomerName.Text;
            this.rbIsFCPA.Visible = false;
            this.lbIsFCPAReadOnly.Text = this.rbIsFCPA.SelectedItem.Text;
            this.tbCustomerCountry.Visible = false;
            this.lbCustomerCountryReadOnly.Text = this.tbCustomerCountry.Text;
            this.tbVisitObjectives.Visible = false;
            this.lbVisitObjectivesReadOnly.Text = this.tbVisitObjectives.Text;
            this.tbPotentialRevenue.Visible = false;
            this.lbPotentialRevenueReadOnly.Text = this.tbPotentialRevenue.Text;
            this.ddlPotentialRevenueTime.Visible = false;
            this.lbPotentialRevenueTimeReadOnly.Text = this.ddlPotentialRevenueTime.SelectedItem.Text;
            this.ddlSaleStage.Visible = false;
            this.lbSaleStageReadOnly.Text = this.ddlSaleStage.SelectedItem.Text;
            this.rbOutStandingRFP.Visible = false;
            this.lbOutStandingRFPReadOnly.Text = this.rbOutStandingRFP.SelectedItem.Text;
            this.tbSensitiveIssues.Visible = false;
            this.lbSeneitiveIssuesReadOnly.Text = this.tbSensitiveIssues.Text;
            this.tbKeyMessage.Visible = false;
            this.lbKeyMessageReadOnly.Text = this.tbKeyMessage.Text;
            this.tbCompanyProfile.Visible = false;
            this.lbCompanyProfileReadOnly.Text = this.tbCompanyProfile.Text;
            this.ddlAccountType.Visible = false;
            this.lbAccountTypeReadOnly.Text = this.ddlAccountType.SelectedItem.Text;
            this.tbProposalNo.Visible = false;
            this.lbProposalNoReadOnly.Text = this.tbProposalNo.Text;
            this.rbIsSensitiveIssue.Visible = false;
            this.lbIsSensitiveIssue.Text = this.rbIsSensitiveIssue.SelectedItem.Text;
            this.lbSeneitiveIssuesReadOnly.Text = this.tbSensitiveIssues.Text;

            // Business Purpose
            this.rbSalesContract.Visible = false;
            this.lbSalesContractReadOnly.Text = this.rbSalesContract.SelectedItem.Text;
            this.rbSalesContractSigned.Visible = false;
            this.lbSalesContractSignedReadOnly.Text = this.rbSalesContractSigned.SelectedItem.Text;
            this.tbNotSalesContractDescription.Visible = false;
            this.lbNotSalesContractDescriptionReadOnly.Text = this.tbNotSalesContractDescription.Text;
            this.rbActivityInTrip.Visible = false;
            this.lbActivityInTripReadOnly.Text = this.rbActivityInTrip.SelectedItem.Text;
            this.rbALInvitation.Visible = false;
            this.lbALInvitationReadOnly.Text = this.rbALInvitation.SelectedItem.Text;

            // Topic
            this.tbTopic.Visible = false;
            this.lbTopicReadOnly.Text = this.tbTopic.Text;

            // Sales Team
            this.tbCustomerTeamHost.Visible = false;
            this.lbCustomerTeamHostReadOnly.Text = this.tbCustomerTeamHost.Text;
            this.tbCustomerOfficeTel.Visible = false;
            this.lbCustomerOfficeTelReadOnly.Text = this.tbCustomerOfficeTel.Text;
            this.tbCustomerFax.Visible = false;
            this.lbCustomerFaxReadOnly.Text = this.tbCustomerFax.Text;
            this.tbCustomerEmail.Visible = false;
            this.lbCustomerEmailReadOnly.Text = this.tbCustomerEmail.Text;
            this.ddlSalesBusinessUnit.Visible = false;
            this.lbSalesBusinessUnitReadOnly.Text = this.ddlSalesBusinessUnit.SelectedItem.Text;
            this.ddlRegion.Visible = false;
            this.lbRegionReadOnly.Text = this.ddlRegion.SelectedItem.Text;
            this.tbOtherCountry.Visible = false;
            this.lbOtherCountryReadOnly.Text = this.tbOtherCountry.Text;

            // LogisticalInfo
            this.rbEntertainmentNeed.Visible = false;
            this.lbEntertainmentNeedReadOnly.Text = this.rbEntertainmentNeed.SelectedItem.Text;
            this.tbPreferEntertainment.Visible = false;
            this.lbPreferEntertainmentReadOnly.Text = this.tbPreferEntertainment.Text;
            this.tbEntertainmentPriceRangeFrom.Visible = false;
            this.lbEntertainmentPriceRangeFromReadOnly.Text = this.tbEntertainmentPriceRangeFrom.Text;
            this.tbEntertainmentPriceRangeTo.Visible = false;
            this.lbEntertainmentPriceRangeToReadOnly.Text = this.tbEntertainmentPriceRangeTo.Text;
            this.rbGiftNeed.Visible = false;
            this.lbGiftNeedReadOnly.Text = this.rbGiftNeed.SelectedItem.Text;
            this.tbPreferGift.Visible = false;
            this.lbPreferGiftReadOnly.Text = this.tbPreferGift.Text;
            this.tbGiftPriceRangeFrom.Visible = false;
            this.lbGiftPriceRangeFromReadOnly.Text = this.tbGiftPriceRangeFrom.Text;
            this.tbGiftPriceRangeTo.Visible = false;
            this.lbGiftPriceRangeToReadOnly.Text = this.tbGiftPriceRangeTo.Text;
            this.rbReceivedGift.Visible = false;
            this.lbReceivedGiftReadOnly.Text = this.rbReceivedGift.SelectedItem.Text;
            this.rbInterpreterRequired.Visible = false;
            this.lbInterpreferRequiredReadOnly.Text = this.rbInterpreterRequired.SelectedItem.Text;
            this.rbSimultaneousConsecutive.Visible = false;
            this.lbSimultaneousConsecutiveReadOnly.Text = this.rbSimultaneousConsecutive.SelectedItem.Text;
            this.rbSpecialDialect.Visible = false;
            this.lbSpecialDialectReadOnly.Text = this.rbSpecialDialect.SelectedItem.Text;
            this.rbCateringService.Visible = false;
            this.lbCateringServiceReadOnly.Text = this.rbCateringService.SelectedItem.Text;
            this.tbCaterServiceExplain.Visible = false;
            this.lbCaterServiceExplainReadOnly.Text = this.tbCaterServiceExplain.Text;
            this.tbTravel.Visible = false;
            this.lbTravelReadOnly.Text = this.tbTravel.Text;
            this.tbReceivedGift.Visible = false;
            this.lbReceivedGiftDescriptionReadOnly.Text = this.tbReceivedGift.Text;
            this.tbReceivedGift.Visible = false;
            this.lbReceivedGiftDescriptionReadOnly.Text = this.tbReceivedGift.Text;

            // Payment Info
            this.ddlPayingFor.Visible = false;
            this.lbPayingForReadOnly.Text = this.ddlPayingFor.SelectedItem.Text;
            this.rbDirectToProvider.Visible = false;
            this.lbDirectToProviderReadOnly.Text = this.rbDirectToProvider.SelectedItem.Text;
            this.tbNotDirectReason.Visible = false;
            this.lbNotDirectReasonReadOnly.Text = this.tbNotDirectReason.Text;
            this.tbEstimateTotalCost.Visible = false;
            this.lbEstimateTotalCostReadOnly.Text = this.tbEstimateTotalCost.Text;
            this.tbEstimateCostPerPerson.Visible = false;
            this.lbEstimateCostPerPersonReadOnly.Text = this.tbEstimateCostPerPerson.Text;
            this.tbReason.Visible = false;
            this.lbReasonReadOnly.Text = this.tbReason.Text;

            this.dgCustomerList.Columns[6].Visible = false;
            this.dgALAttendee.Columns[3].Visible = false;
            this.dgCostCenter.Columns[5].Visible = false;
            this.dgContractInfo.Columns[8].Visible = false;
            //			if(!(this.Step == WorkTransition.EBDCV_Close || this.Step == WorkTransition.End))
            //			{
            //				dgCostCenter.Columns[3].Visible = false;
            //				dgCostCenter.Columns[4].Visible = false;
            //			}
        }

        private void BuildApplication(ref Application app, ref CustomerInfo customer, ref BusinessPurpose business,
            ref Topic topic, ref SalesTeamInfo salesTeam, ref LogisticalInfo logist, ref PaymentInfo payment,
            ref IList customerAttendee, ref IList alAttendee, ref IList site, ref IList cost, ref IList contract)
        {
            app.Id = this.AppID;
            app.EZVisitReqNo = string.Empty;
            app.LGDNo = string.Empty;
            app.ApplicationType = WorkflowTypes.EBDCV;
            app.RequesterOfficeTel = this.RequesterInfoControl.OfficePhone;//this.tbRequestOfficeTel.Text.Trim();
            app.RequesterMobile = this.RequesterInfoControl.Mobile;//this.tbRequestorMobile.Text.Trim();
            app.IsReviewedGuideline = this.rbReviewGuideLine.SelectedValue == "1";

            app.RequesterNameEN = this.RequesterInfoControl.NameEN;//this.tbRequestorName.Text.Trim();
            if (this.tbRequestedDateFrom.Text != string.Empty)
                app.RequestedDateFrom = Convert.ToDateTime(this.tbRequestedDateFrom.Text);
            if (this.tbRequestedDateTo.Text != string.Empty)
                app.RequestedDateTo = Convert.ToDateTime(this.tbRequestedDateTo.Text);
            if (this.tbAlternateDateFrom.Text != string.Empty)
                app.AlternateDateFrom = Convert.ToDateTime(this.tbAlternateDateFrom.Text);
            if (this.tbAlternateDateTo.Text != string.Empty)
                app.AlternateDateTo = Convert.ToDateTime(this.tbAlternateDateTo.Text);
            app.AppNo = this.ApplicationNo;

            app.IsSSME = this.rbIsEBD.SelectedValue == "1";
            IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
            // Apply for someone else
            if (this.rbSomeoneElse.SelectedValue == "1")
            {
                if (this.SearchStaff.EmployeeName != string.Empty)
                {
                    //					app.DepartmentName = this.GetUser(this.SearchStaff.EmployeeName).Department;
                    app.SomeoneElseNo = new Employee();
                    app.SomeoneElseNo.Id = this.SearchStaff.EmployeeID;
                    app.SomeoneElseNameEN = this.SearchStaff.EmployeeName;
                }

                app.ApplyForSomeoneElse = true;
                app.SomeoneElseTel = this.tbSomeoneTel.Text.Trim();
                app.SomeoneElseEmail = this.tbSomeoneEmail.Text.Trim();
                app.SomeoneElseHRID = this.tbHRID.Text.Trim();
                app.SomeoneElseMobil = this.tbSomeoneMobile.Text.Trim();
            }

            if (app.IsSSME)
            {
                app.CostCenterCode = new DicItem();
                app.CostCenterCode.Id = Convert.ToInt32(this.ddlCostCenter.SelectedValue);
                app.CostCenterCode.DicItemKey = this.ddlCostCenter.SelectedItem.Text;
                app.DepartmentType = null;
                app.DepartmentName = query.GetDepartmentByCostCenter(this.ddlCostCenter.SelectedItem.Text);
            }
            else
            {
                app.CostCenterCode = null;
                app.DepartmentType = new DicItem();
                app.DepartmentType.Id = Convert.ToInt32(this.ddlDepartment.SelectedValue);
                app.DepartmentType.DicItemKey = this.ddlDepartment.SelectedItem.Text;
                app.DepartmentName = query.GetDepartmentByCode(this.ddlDepartment.SelectedItem.Text);
            }

            app.LegalEntity = new LegalEntity();
            app.LegalEntity.Id = Convert.ToInt32(this.ddlLegalEntity.SelectedValue);
            app.NeedEVPApproval = this.NeedSSMEApprove;
            app.OtherCountry = this.tbOtherCountry.Text;
            app.BUHeadApproved = this.rbBUHeadApproval.SelectedValue == "1";

            IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
            app.RequesterNo = userService.GetUser(app.RequesterNameEN);

            // Customer Info
            customer.Id = this.CustomerID;
            customer.Company = this.tbCustomerName.Text.Trim();
            customer.IsFCPA = this.rbIsFCPA.SelectedValue == "1";
            customer.Country = this.tbCustomerCountry.Text.Trim();
            customer.NumberOfPerson = this.lbGuestNumberReadOnly.Text.Trim();
            customer.VisitObjective = this.tbVisitObjectives.Text.Trim();
            if (this.tbPotentialRevenue.Text != string.Empty)
                customer.DecryptedRevenuePotential = Convert.ToDecimal(this.tbPotentialRevenue.Text);
            customer.PotentialRevenueTimeframe = Convert.ToInt32(this.ddlPotentialRevenueTime.SelectedValue);
            customer.SalesStage = Convert.ToInt32(this.ddlSaleStage.SelectedValue);
            customer.IsInRFP = this.rbOutStandingRFP.SelectedValue == "1";
            customer.IsThereSensitiveIssue = this.tbSensitiveIssues.Text.Trim();
            customer.IsKeyMessage = this.rbKeyMessage.SelectedValue == "1";
            customer.IsThereKeyMessage = this.tbKeyMessage.Text.Trim();
            customer.CompanyProfile = this.tbCompanyProfile.Text.Trim();
            customer.AccountType = new DicItem();
            customer.AccountType.Id = Convert.ToInt32(this.ddlAccountType.SelectedValue);
            customer.ProposalNo = this.tbProposalNo.Text.Trim();
            customer.IsSensitiveIssue = this.rbIsSensitiveIssue.SelectedValue == "1";
            customer.IsThereSensitiveIssue = this.tbSensitiveIssues.Text.Trim();

            // BusinessPurpose
            business.Id = this.BusinessID;
            business.IsInSalesContract = this.rbSalesContract.SelectedValue == "1";
            business.IsContractSigned = this.rbSalesContractSigned.SelectedValue == "1";
            business.RecreationalActivity = this.rbActivityInTrip.SelectedValue == "1";
            business.IsNeedInvitationLetter = this.rbALInvitation.SelectedValue == "1";
            business.Opportunities = this.tbNotSalesContractDescription.Text.Trim();

            // Topic 
            topic.Id = this.TopicID;
            topic.TopicName = this.tbTopic.Text.Trim();

            // SalesTeam
            salesTeam.Id = this.SalesTeamID;
            salesTeam.HostNameEN = this.tbCustomerTeamHost.Text.Trim();
            salesTeam.OfficeTel = this.tbCustomerOfficeTel.Text.Trim();
            salesTeam.OfficeFax = this.tbCustomerFax.Text.Trim();
            salesTeam.Email = this.tbCustomerEmail.Text.Trim();
            salesTeam.SalesBusinessUnit = this.ddlSalesBusinessUnit.SelectedValue;
            salesTeam.Region = this.ddlRegion.SelectedValue;

            // LogisticalInfo
            logist.Id = this.LogistID;
            logist.IsNeedEntertainment = this.rbEntertainmentNeed.SelectedValue == "1";
            logist.EntertainmentPreference = this.tbPreferEntertainment.Text.Trim();
            if (this.tbEntertainmentPriceRangeFrom.Text != string.Empty)
                logist.DecryptedEntertainmentPriceFrom = Convert.ToDecimal(this.tbEntertainmentPriceRangeFrom.Text);
            if (this.tbEntertainmentPriceRangeTo.Text != string.Empty)
                logist.DecryptedEntertainmentPriceTo = Convert.ToDecimal(this.tbEntertainmentPriceRangeTo.Text);
            logist.IsNeedGift = this.rbGiftNeed.SelectedValue == "1";
            logist.GiftPreference = this.tbPreferGift.Text;
            if (this.tbGiftPriceRangeFrom.Text != string.Empty)
                logist.DecryptedGiftPriceFrom = Convert.ToDecimal(this.tbGiftPriceRangeFrom.Text);
            if (this.tbGiftPriceRangeTo.Text != string.Empty)
                logist.DecryptedGiftPriceTo = Convert.ToDecimal(this.tbGiftPriceRangeTo.Text);
            logist.IsReceivedALGiftBefore = this.rbReceivedGift.SelectedValue == "1";
            logist.ReceivedGiftDetails = this.tbReceivedGift.Text;
            logist.IsNeedInterpreter = this.rbInterpreterRequired.SelectedValue == "1";
            logist.InterpretionType = Convert.ToInt32(this.rbSimultaneousConsecutive.SelectedValue);
            logist.SpecialDialect = this.rbSpecialDialect.SelectedValue;
            logist.IsNeedCatering = this.rbCateringService.SelectedValue == "1";
            logist.CateringDescription = this.tbCaterServiceExplain.Text.Trim();
            logist.TravelAgency = this.tbTravel.Text.Trim();

            // Payment Info
            payment.Id = this.PaymentID;
            payment.Payer = Convert.ToInt32(this.ddlPayingFor.SelectedValue);
            payment.IsPayServiceProvider = this.rbDirectToProvider.SelectedValue == "1";
            payment.NotDirectPayReasons = this.tbNotDirectReason.Text.Trim();
            if (this.tbEstimateTotalCost.Text != string.Empty)
                payment.DecryptedEstimatedCustomerTotalCost = Convert.ToDecimal(this.tbEstimateTotalCost.Text);
            if (this.tbEstimateCostPerPerson.Text != string.Empty)
                payment.DecryptedEstimateCustomerdIndividualCost = Convert.ToDecimal(this.tbEstimateCostPerPerson.Text);
            payment.CustomerPerdiem = this.tbReason.Text.Trim();

            // site info
            for (int i = 0; i < this.cblPreferredLocation.Items.Count; i++)
            {
                if (cblPreferredLocation.Items[i].Selected)
                {
                    AppVisitingSite appSite = new AppVisitingSite();
                    appSite.Site = new DicItem();
                    appSite.Site.Id = Convert.ToInt32(cblPreferredLocation.Items[i].Value);

                    site.Add(appSite);
                }
            }

            // Customer Attendee Info
            DataTable table = (DataTable)this.dgCustomerList.DataSource;
            if (table != null && table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    CustomerAttendee cus = new CustomerAttendee();
                    cus.NameCN = table.Rows[i]["NameCN"].ToString();
                    cus.Title = table.Rows[i]["Title"].ToString();
                    cus.Company = table.Rows[i]["Company"].ToString();
                    cus.NameEN = table.Rows[i]["Name"].ToString();
                    cus.TitleEN = table.Rows[i]["TitleEN"].ToString();
                    cus.CompanyEN = table.Rows[i]["CompanyEN"].ToString();
                    cus.Responsibility = new DicItem();
                    cus.Responsibility.Id = Convert.ToInt32(table.Rows[i]["ResponsibilityID"]);
                    cus.Affects = new DicItem();
                    cus.Affects.Id = Convert.ToInt32(table.Rows[i]["AffectsID"]);
                    cus.IsAttended = true;

                    cus.Remark = table.Rows[i]["Remark"].ToString();
                    cus.IsExisted = Convert.ToInt32(table.Rows[i]["IsExisted"]);

                    customerAttendee.Add(cus);
                }
            }

            // AL Attendee Info
            table = (DataTable)this.dgALAttendee.DataSource;
            if (table != null && table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    ALAttendee al = new ALAttendee();
                    al.EmployeeId = new Employee();
                    al.EmployeeId.Id = table.Rows[i]["EmployeeId"].ToString();
                    al.Title = table.Rows[i]["Title"].ToString();

                    alAttendee.Add(al);
                }
            }

            // Cost Center Info
            table = (DataTable)this.dgCostCenter.DataSource;
            if (table != null && table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    CostCenterRelatedCost co = new CostCenterRelatedCost();
                    co.CostCenterCode = table.Rows[i]["CostCenterCode"].ToString();
                    co.DecryptedCost = Convert.ToDecimal(table.Rows[i]["Cost"]);
                    co.CostType = CostType.Budget;

                    cost.Add(co);
                }
            }

            // Contract Info
            table = (DataTable)this.dgContractInfo.DataSource;
            if (table != null && table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    ContractInfo ci = new ContractInfo();
                    ci.DateOfContract = Convert.ToDateTime(table.Rows[i]["DateOfContract"]);
                    ci.ContractNo = table.Rows[i]["ContractNo"].ToString();
                    ci.ProducstSold = table.Rows[i]["ProducstSold"].ToString();
                    ci.VisitPurposeInContract = table.Rows[i]["VisitPurposeInContract"].ToString();
                    ci.Quotas = Convert.ToInt32(table.Rows[i]["Quotas"]);
                    ci.UnitPrice = Convert.ToDecimal(table.Rows[i]["UnitPrice"]);
                    ci.Budget = Convert.ToDecimal(table.Rows[i]["Budget"]);

                    contract.Add(ci);
                }
            }
        }


        public bool DatasValidation()
        {
            if (this.dgCustomerList.DataSource == null || ((DataTable)this.dgCustomerList.DataSource).Rows.Count == 0)
            {
                Page.RegisterClientScriptBlock("", "<script>alert('At least one customer should be specified.');</script>");
                return false;
            }
            if (this.dgALAttendee.DataSource == null || ((DataTable)this.dgALAttendee.DataSource).Rows.Count == 0)
            {
                Page.RegisterClientScriptBlock("", "<script>alert('At least one AL attendee should be specified.');</script>");
                return false;
            }
            if (this.dgCostCenter.DataSource == null || ((DataTable)this.dgCostCenter.DataSource).Rows.Count == 0)
            {
                Page.RegisterClientScriptBlock("", "<script>alert('At least one cost center should be specified.');</script>");
                return false;
            }
            if (this.rbSalesContract.SelectedValue == "1")
            {
                if (this.dgContractInfo.DataSource == null || ((DataTable)this.dgContractInfo.DataSource).Rows.Count == 0)
                {
                    Page.RegisterClientScriptBlock("", "<script>alert('At least one contract information should be specified.');</script>");
                    return false;
                }
            }
            if (this.Lb_CISWarning.Visible == true)
            {
                Page.RegisterClientScriptBlock("", "<script>alert('There are customer(s) not in CIS.');</script>");
                return false;
            }

            return true;
        }
        public void Save()
        {
            try
            {
                IEBDCV ocvService = AppContainer.Instance[ServiceConst.EBDCVService] as IEBDCV;

                Application app = new Application();
                CustomerInfo customer = new CustomerInfo();
                BusinessPurpose business = new BusinessPurpose();
                Topic topic = new Topic();
                SalesTeamInfo salesTeam = new SalesTeamInfo();
                LogisticalInfo logist = new LogisticalInfo();
                PaymentInfo payment = new PaymentInfo();
                IList customerAttendee = new ArrayList();
                IList alAttendee = new ArrayList();
                IList site = new ArrayList();
                IList cost = new ArrayList();
                IList contract = new ArrayList();

                BuildApplication(ref app, ref customer, ref business, ref topic, ref salesTeam, ref logist, ref payment,
                    ref customerAttendee, ref alAttendee, ref site, ref cost, ref contract);
                ocvService.Save(app, customer, business, topic, salesTeam, logist, payment, customerAttendee, alAttendee, site, cost, contract);
                this.AppID = app.Id;
                this.CustomerID = customer.Id;
                this.BusinessID = business.Id;
                this.TopicID = topic.Id;
                this.SalesTeamID = salesTeam.Id;
                this.LogistID = logist.Id;
                this.PaymentID = payment.Id;
                this.ApplicationNo = app.AppNo;
                this.ctrlExport.Visible = true;
                this.Application = app;

            }
            catch (Exception ex)
            {
                Page.RegisterClientScriptBlock("", "<script>alert('" + BEGDC.CC.Resource.SystemMessage.CV002 + "');</script>");
            }
        }

        public void AfterSave()
        {
            Session["AppID"] = this.Application.Id;

            string url = string.Empty + Request.Form["tbURL"];
            string script = "<script>";
            if (url == string.Empty)
                script += "VBAlert('" + BEGDC.CC.Resource.SystemMessage.CM001 + "');";
            if (url != string.Empty)
            {
                if (url.IndexOf("AppID") == -1)
                    url = url.Substring(0, url.IndexOf("?") + 1) + "AppID=" + this.Application.Id + "&" + url.Substring(url.IndexOf("?") + 1);
                script += "window.location.href='" + url + "'";
            }
            else
            {
                url = Request.Url.AbsoluteUri;
                if (url.IndexOf("AppID") == -1)
                {
                    url = url.Substring(0, url.IndexOf("?") + 1) + "AppID=" + this.Application.Id + "&" + url.Substring(url.IndexOf("?") + 1);
                    script += "window.location.href='" + url + "'";
                }
            }
            script += "</script>";

            Page.RegisterClientScriptBlock("", script);
        }


        private void dgCustomerList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                ImageButton Btn_Edit = (ImageButton)e.Item.Cells[12].FindControl("Btn_Edit");
                string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenCustomerPane('" + ItemId + "');");
                Btn_Edit.Attributes.Add("check", "false");

                ImageButton ld = (ImageButton)e.Item.Cells[12].FindControl("Btn_Delete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                    ld.Attributes.Add("check", "false");
                }

                string IsExisted = e.Item.Cells[6].Text.ToString();
                if (IsExisted == BEGDC.CC.BL.Common.CISFlag.NotExisted)
                {
                    System.Web.UI.WebControls.Image WarningImg = (System.Web.UI.WebControls.Image)e.Item.Cells[11].FindControl("CISWarning");
                    WarningImg.Visible = true;
                }
                if (IsExisted == "2")
                {
                    System.Web.UI.WebControls.Image WarningImg = (System.Web.UI.WebControls.Image)e.Item.Cells[11].FindControl("RedWarning");
                    WarningImg.Visible = true;
                }
                LinkButton lb = (LinkButton)e.Item.Cells[8].FindControl("lb_AttendeeCount");
                if (lb != null)
                {
                    lb.Text = e.Item.Cells[7].Text;
                    Session["Attendee_CustomerName"] = e.Item.Cells[1].Text;
                    Session["Attendee_CustomerCompany"] = e.Item.Cells[2].Text;
                    string customerName = System.Web.HttpUtility.UrlEncode(e.Item.Cells[1].Text.Replace(" ", "_"), System.Text.Encoding.UTF8);
                    string companyName = System.Web.HttpUtility.UrlEncode(e.Item.Cells[2].Text.Replace(" ", "_"), System.Text.Encoding.UTF8);
                    lb.Attributes.Add("onclick", "javascript:OpenApplicationPane('" + customerName + "','" + companyName + "');");
                }
            }
        }

        private void dgALAttendee_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                ImageButton Btn_Edit = (ImageButton)e.Item.Cells[3].FindControl("Btn_ALEdit");
                string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenALAttendeePane('" + ItemId + "');");
                Btn_Edit.Attributes.Add("check", "false");

                ImageButton ld = (ImageButton)e.Item.Cells[3].FindControl("Btn_ALDelete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                    ld.Attributes.Add("check", "false");
                }
            }
        }


        private void dgCostCenter_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                ImageButton Btn_Edit = (ImageButton)e.Item.Cells[3].FindControl("Btn_CostEdit");
                string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenCostCenterPane('" + ItemId + "');");

                ImageButton ld = (ImageButton)e.Item.Cells[4].FindControl("Btn_CostDelete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                }
            }
        }

        private void dgContractInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                ImageButton Btn_Edit = (ImageButton)e.Item.Cells[8].FindControl("Btn_ContractEdit");
                string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenContractPane('" + ItemId + "');");
                Btn_Edit.Attributes.Add("check", "false");

                ImageButton ld = (ImageButton)e.Item.Cells[8].FindControl("Btn_ContractDelete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                    ld.Attributes.Add("check", "false");
                }
            }
        }

        private Employee GetUser(string name)
        {
            IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
            return userService.GetUser(name);
        }

        private void ControlStatusSetting(Accessibility access)
        {
            if (access == Accessibility.Readonly)
            {
                this.DisableChildrenControls(this);
            }
        }

        private void dgContractInfo_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = Convert.ToInt32(e.Item.Cells[0].Text);

                DataTable contractInfo = (DataTable)Session[SessionFlag.ContractInfo];
                DataRow contractRow = contractInfo.Rows[rowid - 1];
                contractInfo.Rows.Remove(contractRow);
                this.BindContractInfo();
            }
            catch
            {
            }
        }

        private void dgCustomerList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = Convert.ToInt32(e.Item.Cells[0].Text);

                DataTable contractInfo = (DataTable)Session[SessionFlag.CustomerSessionEZ];
                DataRow contractRow = contractInfo.Rows[rowid - 1];
                contractInfo.Rows.Remove(contractRow);
                this.BindCustomerAttendee();
            }
            catch
            {
            }
        }

        private void dgALAttendee_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = Convert.ToInt32(e.Item.Cells[0].Text);

                DataTable contractInfo = (DataTable)Session[SessionFlag.AccompanySessionEZ];
                DataRow contractRow = contractInfo.Rows[rowid - 1];
                contractInfo.Rows.Remove(contractRow);
                this.BindALAttendee();
            }
            catch
            {
            }
        }

        private void dgCostCenter_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = Convert.ToInt32(e.Item.Cells[0].Text);

                DataTable contractInfo = (DataTable)Session[SessionFlag.CostCenter];
                DataRow contractRow = contractInfo.Rows[rowid - 1];
                contractInfo.Rows.Remove(contractRow);
                this.BindCostCenter();
            }
            catch
            {
            }
        }


        public void ShowModifyStatus()
        {
            this.ALPaneImg.Visible = true;
            this.CustomerPaneImg.Visible = true;
            this.tbRequestedDateFrom.Visible = true;
            this.tbRequestedDateTo.Visible = true;
            this.lbRequestedDateFromReadOnly.Visible = false;
            this.lbRequestedDateToReadOnly.Visible = false;
            img2.Visible = true;
            img3.Visible = true;
        }

        public void EndModifyStatus()
        {
            this.ALPaneImg.Visible = false;
            this.CustomerPaneImg.Visible = false;
            this.tbRequestedDateFrom.Visible = false;
            this.tbRequestedDateTo.Visible = false;
            img2.Visible = false;
            img3.Visible = false;
            this.lbRequestedDateFromReadOnly.Text = this.tbRequestedDateFrom.Text;
            this.lbRequestedDateToReadOnly.Text = this.tbRequestedDateTo.Text;
            this.lbRequestedDateFromReadOnly.Visible = true;
            this.lbRequestedDateToReadOnly.Visible = true;
        }

        protected override void ButtonStatusSetting()
        {
            if (this.Access != null)
            {
                if ((this.Access.IsReadOnly || this.IsView))
                    BindReadOnlyStatus();
            }
            else
            {
                if ((this.isReadOnly || this.IsView))
                    BindReadOnlyStatus();
            }

        }

        private void SetAppID(int appid)
        {
            this.Access.AppId = appid;
        }


        private string CalculateSum()
        {
            decimal sum = 0;
            DataTable table = (DataTable)this.dgContractInfo.DataSource;
            if (table != null)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    sum += Convert.ToDecimal(table.Rows[i]["Budget"]);
                }
            }

            return sum.ToString("0.00");
        }

        private string CalculateCostSum()
        {
            decimal sum = 0;
            DataTable table = (DataTable)this.dgCostCenter.DataSource;
            if (table != null)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    sum += Convert.ToDecimal(table.Rows[i]["Cost"]);
                }
            }

            return sum.ToString("0.00");
        }

        public void SetCloseControlVisiable()
        {
            this.closectl1.Visible = true;
        }

        public void SaveCloseControl()
        {
            this.closectl1.SaveApplication();
        }

        public void BindCloseControl()
        {
            this.closectl1.BindApplication();
            this.closectl1.BindCostCenter();
        }
        public BEGDC.CC.Entity.Application GetApplication()
        {
            return this.Application;
        }

        public void DisableSSME()
        {
            this.rbIsEBD.Enabled = false;
            this.ddlCostCenter.Enabled = false;
            this.ddlDepartment.Enabled = false;
            this.span6.Visible = false;
            this.span7.Visible = false;
        }

        public void NeedSSMEEVPApprove()
        {
            this.NeedSSMEApprove = true;
        }

        public void SetCloseControlEnable()
        {
            this.closectl1.SetEnableStatus();
        }
    }
}
